package com.cleaningcloud.erp.controller;

import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.domain.dto.StatisticsQueryDto;
import com.cleaningcloud.erp.domain.statistics.*;
import com.cleaningcloud.erp.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 统计
 *
 * @author cleaningcloud
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/statistics")
public class StatisticsController extends BaseController {

    @Autowired
    private StatisticsService statisticsService;
    /**
     * 出库统计
     */
    @RequiresPermissions("erp:statistics:outbound")
    @GetMapping("/OutboundStatistics")
    public TableDataInfo OutboundStatistics(OutboundStatistics outboundStatistics)
    {
        startPage();
        List<OutboundStatistics> list = statisticsService.outboundStatistics(outboundStatistics);
        return getDataTable(list);
    }
    @RequiresPermissions("erp:statistics:export")
    @Log(title = "出库统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportOutbound")
    public void exportSale(HttpServletResponse response, OutboundStatistics outboundStatistics)
    {
        List<OutboundStatistics> list = statisticsService.outboundStatistics(outboundStatistics);
        ExcelUtil<OutboundStatistics> util = new ExcelUtil<>(OutboundStatistics.class);
        util.exportExcel(response, list, "出库统计");
    }

    /**
     * 销售统计
     */
    @RequiresPermissions("erp:statistics:sale")
    @GetMapping("/SaleStatistics")
    public TableDataInfo SaleStatistics(SaleStatistics saleStatistics)
    {
        startPage();
        List<SaleStatistics> list = statisticsService.saleStatistics(saleStatistics);
        return getDataTable(list);
    }

    @RequiresPermissions("erp:statistics:export")
    @Log(title = "销售统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSale")
    public void exportSale(HttpServletResponse response, SaleStatistics saleStatistics)
    {
        List<SaleStatistics> list = statisticsService.saleStatistics(saleStatistics);
        ExcelUtil<SaleStatistics> util = new ExcelUtil<>(SaleStatistics.class);
        util.exportExcel(response, list, "销售统计");
    }



    /**
     * 入库统计
     */
    @RequiresPermissions("erp:statistics:warehousing")
    @GetMapping("/WarehousingStatistics")
    public TableDataInfo WarehousingStatistics(WarehousingStatistics warehousingStatistics)
    {
        startPage();
        List<WarehousingStatistics> list = statisticsService.warehousingStatistics(warehousingStatistics);
        return getDataTable(list);
    }

    /**
     * 导出入库统计列表
     */
    @RequiresPermissions("erp:statistics:export")
    @Log(title = "入库统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportWarehousing")
    public void exportWarehousing(HttpServletResponse response, WarehousingStatistics warehousingStatistics)
    {
        List<WarehousingStatistics> list = statisticsService.warehousingStatistics(warehousingStatistics);
        ExcelUtil<WarehousingStatistics> util = new ExcelUtil<>(WarehousingStatistics.class);
        util.exportExcel(response, list, "入库统计");
    }


    /**
     * 采购统计
     */
    @RequiresPermissions("erp:statistics:procure")
    @GetMapping("/ProcureStatistics")
    public TableDataInfo ProcureStatistics(ProcureStatistics procureStatistics)
    {
        startPage();
        List<ProcureStatistics> list = statisticsService.procureStatistics(procureStatistics);
        return getDataTable(list);
    }

    /**
     * 导出采购统计列表
     */
    @RequiresPermissions("erp:statistics:export")
    @Log(title = "采购统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportProcure")
    public void exportProcure(HttpServletResponse response, ProcureStatistics procureStatistics)
    {
        List<ProcureStatistics> list = statisticsService.procureStatistics(procureStatistics);
        ExcelUtil<ProcureStatistics> util = new ExcelUtil<>(ProcureStatistics.class);
        util.exportExcel(response, list, "采购统计");
    }

    /**
     * 库存统计 - 仓库统计
     */
    @GetMapping("/WareStatistics")
    public AjaxResult WareStatistics(StatisticsQueryDto statisticsQueryDto)
    {
        List<Map<String,Object>> list = statisticsService.wareStatistics(statisticsQueryDto);
        return success(list);
    }

    /**
     * 库存统计 - 商品统计
     */
    @GetMapping("/StockStatistics")
    public TableDataInfo StockStatistics(StatisticsQueryDto statisticsQueryDto)
    {
        startPage();
        List<StockStatistics> list = statisticsService.stockStatistics(statisticsQueryDto);
        return getDataTable(list);
    }

    @RequiresPermissions("erp:statistics:export")
    @Log(title = "库存统计", businessType = BusinessType.EXPORT)
    @PostMapping("/exportStock")
    public void exportStock(HttpServletResponse response, StatisticsQueryDto statisticsQueryDto)
    {
        List<StockStatistics> list = statisticsService.stockStatistics(statisticsQueryDto);
        ExcelUtil<StockStatistics> util = new ExcelUtil<>(StockStatistics.class);
        util.exportExcel(response, list, "库存统计");
    }

    /**
     * 库存统计 - 商品统计
     */
    @GetMapping("/stockHeadStatistics")
    public AjaxResult stockHeadStatistics()
    {
        return success(statisticsService.stockHeadStatistics());
    }
}
